package cn.xsly.ymcc.web.controller;

import cn.xsly.ymcc.doc.CourseDoc;
import cn.xsly.ymcc.dto.SearchParamDto;
import cn.xsly.ymcc.result.JSONResult;
import cn.xsly.ymcc.result.PageList;
import cn.xsly.ymcc.service.ICourseDocService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/search")
public class SerachCourseController {
    @Autowired
    private ICourseDocService courseDocService;

    @PostMapping("/save")
    public JSONResult save(@RequestBody CourseDoc doc) {
        courseDocService.save(doc);
        return JSONResult.success();
    }
    @PostMapping("/delete")
    public JSONResult delete(@RequestBody CourseDoc doc) {
        courseDocService.delete(doc);
        return JSONResult.success();
    }


    @PostMapping("/course")
    public JSONResult courseSearch(@RequestBody SearchParamDto dto){
        PageList<CourseDoc> pageList = courseDocService.searchCourse(dto);
        return JSONResult.success(pageList);
    }
}
